// components/modify-confirm/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    confirmList: {
      type: Array,
      value: [],
      observer: 'setDataSource'
    },
    recordId: {
      type: Number,
      observer: 'idChange'
    },
    enable: {
      type: Boolean,
      type: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    idChange(i){
      console.log(i)
    },
    onClose() {
      this.triggerEvent('onClose');
    },
    setDataSource(data) {
      this.setData({
        list: data
      })
 
    },

    onConfirm(event) {
      const index = event.currentTarget.dataset.index,
        data = [...this.data.list];
      data[index].state = false;
      this.setData({
        list: data
      })
      const valid = this.data.list.every(it=>{
        return it.state === false
      })
 
      if(valid) {
        this.triggerEvent('onClose' ,true);
        return 
      }
    },
    goto(event) {
      const {
        name,
        path,
      } = event.currentTarget.dataset.item;
      const id = this.properties.recordId;
      console.log(id)
      if (name === '釉料2') {
        wx.navigateTo({
          url: `${path}?id=${id}&next=firing&sortNumber=1&pageTitle=胚体釉料2&navigation=1`
        })  
      } else {
        wx.navigateTo({
          url: `${path}?id=${id}&navigation=1`,
        })
      }
    }
  }
})